// window.ailin_get_Install_Shortcut_Prefab = function () {
//     var e = new cc.Node();
//     e.on(cc.Node.EventType.TOUCH_END, function () {
//         e.callFun();
//     });
//     e.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/bg", function (t, o) {
//         e.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
//     });
//     var t = new cc.Node();
//     var o = new cc.Node();
//     var i = new cc.Node();
//     e.addChild(t);
//     e.addChild(o);
//     e.addChild(i);
//     t.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/heartBg", function (e, o) {
//         t.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
//     });
//     o.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/heart", function (e, t) {
//         o.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     i.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/figer", function (e, t) {
//         i.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     t.y = 12;
//     o.y = 12;
//     i.y = -110;
//     t.runAction(
//         cc.repeatForever(
//             cc.sequence(
//                 cc.callFunc(function () {
//                     t.opacity = 255;
//                     t.scale = 1;
//                 }),
//                 cc.spawn(cc.scaleTo(0.8, 3), cc.fadeOut(0.8))
//             )
//         )
//     );
//     i.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.5, 0, -40), cc.moveBy(0.5, 0, 40))));
//     return e;
// };
// window.ailin_get_Install_Shortcut_Prefab = function () {
//     var e = new cc.Node();
//     var t = new cc.Node();
//     e.addChild(t);
//     t.addComponent(cc.BlockInputEvents);
//     t.addComponent(cc.Sprite);
//     t.opacity = 50;
//     ailin_load("q_ad/oppo_native_insters_layerBg.png", function (e, o) {
//         t.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
//         t.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         t.width = cc.winSize.width;
//         t.height = cc.winSize.height;
//     });
//     var o = new cc.Node();
//     e.scale = ailin_sdk_manager._SceneScale;
//     t.scale = 1 / ailin_sdk_manager._SceneScale;
//     e.addChild(o);
//     o.addComponent(cc.Sprite);
//     ailin_load("q_ad/bg.png", function (e, t) {
//         o.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         o.getComponent(cc.Sprite).spriteFrame.insetTop = 100;
//         o.getComponent(cc.Sprite).spriteFrame.insetBottom = 20;
//         o.getComponent(cc.Sprite).spriteFrame.insetLeft = 50;
//         o.getComponent(cc.Sprite).spriteFrame.insetRight = 50;
//         o.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         o.getComponent(cc.Sprite).type = cc.Sprite.Type.SLICED;
//         o.width = 650;
//         o.height = 400;
//     });
//     var i = new cc.Node();
//     o.addChild(i);
//     i.y = -80;
//     i.addComponent(cc.Sprite);
//     ailin_load("q_ad/touch.png", function (e, t) {
//         i.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         i.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         i.width = 354 * 0.7;
//         i.height = 117 * 0.7;
//     });
//     var n = new cc.Node();
//     o.addChild(n);
//     n.x = 0;
//     n.y = -160;
//     n.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/close.png", function (e, t) {
//         n.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         n.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//     });
//     var a = new cc.Node();
//     i.addChild(a);
//     a.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/add.png", function (e, t) {
//         a.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var s = new cc.Node();
//     o.addChild(s);
//     s.y = 160;
//     s.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/title.png", function (e, t) {
//         s.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var r = new cc.Node();
//     o.addChild(r);
//     r.y = 70;
//     r.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/world.png", function (e, t) {
//         r.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var c = new cc.Node();
//     o.addChild(c);
//     c.y = 0;
//     c.x = -25;
//     c.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/day.png", function (e, t) {
//         c.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var l = new cc.Node();
//     var d = new cc.Node();
//     d.active = !1;
//     l.addChild(d);
//     c.addChild(l);
//     l.x = 100;
//     l.addComponent(cc.Sprite);
//     l.on(cc.Node.EventType.TOUCH_START, function () {
//         d.active = !d.active;
//     });
//     ailin_load("anzhuangKuaijieFangShi/okBg.png", function (e, t) {
//         l.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     d.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/ok.png", function (e, t) {
//         d.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     n.on(cc.Node.EventType.TOUCH_START, function () {
//         if (d.active) {
//             var t = ailin_get_time_day();
//             user_default.set_data_for_key("al_not_Show_Install_Shortcut", t);
//         }
//         e.destroy();
//     });
//     i.on(cc.Node.EventType.TOUCH_START, function () {
//         if (d.active) {
//             var t = ailin_get_time_day();
//             user_default.set_data_for_key("al_not_Show_Install_Shortcut", t);
//         }
//         ailin_sdk_manager.instance.anzhuangKuaijieFangShi({
//             canShow: !0,
//             success: function () {
//                 var e = parseInt(10 * Math.random()) + 10;
//                 var t = user_default.get_int_for_key(ailin.Key_Gold, 0);
//                 user_default.set_data_for_key(ailin.Key_Gold, t + e);
//             }
//         });
//         e.destroy();
//     });
//     var u = new cc.Node();
//     u.y = -270;
//     u.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/whiteBg.png", function (e, t) {
//         u.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         u.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         u.width = 600;
//         u.height = 400;
//     });
//     e.addChild(u);
//     u.active = !1;
//     return e;
// };
// window.ailin_get_Install_Shortcut_Dialog_Wx = function (e) {
//     if (void 0 === e) {
//         e = {
//             callFun: null,
//             x: 5e3,
//             h: 4e3,
//             gameName: ""
//         };
//     }
//     var t = new cc.Node();
//     var o = new cc.Node();
//     t.addChild(o);
//     o.addComponent(cc.BlockInputEvents);
//     o.addComponent(cc.Sprite);
//     o.opacity = 50;
//     ailin_load("q_ad/oppo_native_insters_layerBg.png", function (e, t) {
//         o.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         o.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         o.width = cc.winSize.width;
//         o.height = cc.winSize.height;
//     });
//     var i = new cc.Node();
//     t.addChild(i);
//     i.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/di.png", function (e, t) {
//         i.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var n = new cc.Node();
//     i.addChild(n);
//     n.addComponent(cc.Sprite);
//     n.y = -45;
//     ailin_load("anzhuangKuaijieFangShi/icon.png", function (e, t) {
//         n.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     var a = new cc.Node();
//     t.addChild(a);
//     a.x = e.x;
//     a.y = e.h;
//     a.addComponent(cc.Sprite);
//     ailin_load("anzhuangKuaijieFangShi/shouzhi.png", function (e, t) {
//         a.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//         a.runAction(cc.repeatForever(cc.sequence(cc.moveBy(1, cc.v2(20, 0)), cc.moveBy(1, cc.v2(-20, 0)))));
//     });
//     var s = new cc.Node();
//     i.addChild(s);
//     var r = s.addComponent(cc.Label);
//     s.x = 0;
//     s.y = 170;
//     s.color = new cc.Color().fromHEX("#484848");
//     r.fontSize = 30;
//     r.string = "喜欢这个游戏吗？\n快添加到桌面吧";
//     if (e.gameName && "" != e.gameName) {
//         r.string = "喜欢【" + e.gameName + "】吗？\n快添加到桌面吧";
//     }
//     var c = new cc.Node();
//     i.addChild(c);
//     var l = c.addComponent(cc.Label);
//     c.x = 0;
//     c.y = 35;
//     c.width = 360;
//     c.color = new cc.Color().fromHEX("#484848");
//     l.fontSize = 30;
//     l.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
//     l.string = "点击右上角的三个点，选择添加到桌面";
//     var d = new cc.Node();
//     i.addChild(d);
//     d.addComponent(cc.Sprite);
//     d.addComponent(cc.Button);
//     d.y = -170;
//     ailin_load("anzhuangKuaijieFangShi/btn_know.png", function (e, t) {
//         d.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t);
//     });
//     d.on("click", function () {
//         if (e.callFun) {
//             e.callFun();
//         }
//         t.destroy();
//     });
//     t.x = cc.winSize.width / 2;
//     t.y = cc.winSize.height / 2;
//     cc.director.getScene().addChild(t);
//     if (cc.winSize.width < 720) {
//         i.scale = cc.winSize.width / 720;
//     }
//     return t;
// };


// 优化后的代码
window.ailin_get_Install_Shortcut_Prefab = function () {
    const rootNode = new cc.Node();

    rootNode.on(cc.Node.EventType.TOUCH_END, function () {
        rootNode.callFun();
    });

    rootNode.addComponent(cc.Sprite);
    ailin_load("anzhuangKuaijieFangShi/bg", (error, resource) => {
        rootNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(resource);
    });

    const heartBgNode = chuangjian_zijiedian(rootNode, "anzhuangKuaijieFangShi/heartBg", 12);
    const heartNode = chuangjian_zijiedian(rootNode, "anzhuangKuaijieFangShi/heart", 12);
    const node_finger = chuangjian_zijiedian(rootNode, "anzhuangKuaijieFangShi/figer", -110);

    heartBgNode.runAction(cc.repeatForever(
        cc.sequence(
            cc.callFunc(() => {
                heartBgNode.opacity = 255;
                heartBgNode.scale = 1;
            }),
            cc.spawn(cc.scaleTo(0.8, 3), cc.fadeOut(0.8))
        )
    ));

    node_finger.runAction(cc.repeatForever(
        cc.sequence(cc.moveBy(0.5, 0, -40), cc.moveBy(0.5, 0, 40))
    ));

    return rootNode;
};

window.ailin_get_Install_Shortcut_Prefab = function () {
    const rootNode = new cc.Node();
    const backgroundNode = new cc.Node();

    rootNode.addChild(backgroundNode);
    backgroundNode.addComponent(cc.BlockInputEvents);
    backgroundNode.addComponent(cc.Sprite);
    backgroundNode.opacity = 50;

    ailin_load("q_ad/oppo_native_insters_layerBg.png", (error, resource) => {
        const sprite = backgroundNode.getComponent(cc.Sprite);
        sprite.spriteFrame = new cc.SpriteFrame(resource);
        sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
        sprite.width = cc.winSize.width;
        sprite.height = cc.winSize.height;
    });

    rootNode.scale = ailin_sdk_manager._SceneScale;
    backgroundNode.scale = 1 / ailin_sdk_manager._SceneScale;

    const mainNode = chuangjian_zijiedian(rootNode, "q_ad/bg.png", 0, 0);
    mainNode.getComponent(cc.Sprite).type = cc.Sprite.Type.SLICED;
    mainNode.getComponent(cc.Sprite).spriteFrame.setInsetTop(100);
    mainNode.getComponent(cc.Sprite).spriteFrame.setInsetBottom(20);
    mainNode.getComponent(cc.Sprite).spriteFrame.setInsetLeft(50);
    mainNode.getComponent(cc.Sprite).spriteFrame.setInsetRight(50);
    mainNode.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
    mainNode.width = 650;
    mainNode.height = 400;

    chuangjian_zijiedian(mainNode, "q_ad/touch.png", -80);
    chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/close.png", -160).on(cc.Node.EventType.TOUCH_START, function () {
        handle_event_touch_close(rootNode);
    });
    chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/add.png", 0, 0, chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/icon.png", 0, 0));
    chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/title.png", 160);
    chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/world.png", 70);
    chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/day.png", 0, -25);

    const checkboxNode = chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/okBg.png", 0, 100);
    const checkboxInnerNode = chuangjian_zijiedian(checkboxNode, "anzhuangKuaijieFangShi/ok.png", 0, 0);
    checkboxInnerNode.active = false;
    checkboxNode.on(cc.Node.EventType.TOUCH_START, function () {
        checkboxInnerNode.active = !checkboxInnerNode.active;
    });

    const whiteBgNode = chuangjian_zijiedian(rootNode, "anzhuangKuaijieFangShi/whiteBg.png", -270);
    whiteBgNode.width = 600;
    whiteBgNode.height = 400;
    whiteBgNode.active = false;

    return rootNode;
};

window.ailin_get_Install_Shortcut_Dialog_Wx = function (config = { callFun: null, x: 5000, h: 4000, gameName: "" }) {
    const rootNode = new cc.Node();
    const backgroundNode = new cc.Node();

    rootNode.addChild(backgroundNode);
    backgroundNode.addComponent(cc.BlockInputEvents);
    backgroundNode.addComponent(cc.Sprite);
    backgroundNode.opacity = 50;

    ailin_load("q_ad/oppo_native_insters_layerBg.png", (error, resource) => {
        const sprite = backgroundNode.getComponent(cc.Sprite);
        sprite.spriteFrame = new cc.SpriteFrame(resource);
        sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
        sprite.width = cc.winSize.width;
        sprite.height = cc.winSize.height;
    });

    const mainNode = chuangjian_zijiedian(rootNode, "anzhuangKuaijieFangShi/di.png", 0, 0);
    const iconNode = chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/icon.png", -45);
    const textNode = chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/shouzhi.png", config.h, config.x);
    textNode.runAction(cc.repeatForever(cc.sequence(
        cc.moveBy(1, cc.v2(20, 0)),
        cc.moveBy(1, cc.v2(-20, 0))
    )));

    const titleLabelNode = chuangjian_zijiedian_bingtianjia_label(mainNode, "喜欢这个游戏吗？\n快添加到桌面吧", 0, 170);
    if (config.gameName && config.gameName !== "") {
        titleLabelNode.getComponent(cc.Label).string = `喜欢【${config.gameName}】吗？\n快添加到桌面吧`;
    }

    chuangjian_zijiedian_bingtianjia_label(mainNode, "点击右上角的三个点，选择添加到桌面", 0, 35, 360);
    const buttonNode = chuangjian_zijiedian(mainNode, "anzhuangKuaijieFangShi/btn_know.png", -170);
    buttonNode.addComponent(cc.Button);
    buttonNode.on("click", function () {
        if (config.callFun) {
            config.callFun();
        }
        rootNode.destroy();
    });

    rootNode.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);
    cc.director.getScene().addChild(rootNode);

    if (cc.winSize.width < 720) {
        mainNode.scale = cc.winSize.width / 720;
    }

    return rootNode;
};

/**
 * 创建子节点并加载资源
 * @param {cc.Node} parentNode - 父节点
 * @param {string} resourcePath - 资源路径
 * @param {number} posY - Y坐标
 * @param {number} posX - X坐标
 * @param {cc.Node} [child] - 可选子节点
 * @returns {cc.Node} - 创建的子节点
 */
function chuangjian_zijiedian(parentNode, resourcePath, posY = 0, posX = 0, child = null) {
    const childNode = new cc.Node();
    parentNode.addChild(childNode);
    childNode.setPosition(posX, posY);
    childNode.addComponent(cc.Sprite);

    ailin_load(resourcePath, (error, resource) => {
        childNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(resource);
    });

    if (child) {
        childNode.addChild(child);
    }

    return childNode;
}

/**
 * 创建子节点并添加Label组件
 * @param {cc.Node} parentNode - 父节点
 * @param {string} labelText - 显示文本
 * @param {number} posY - Y坐标
 * @param {number} posX - X坐标
 * @param {number} [width] - 可选宽度
 * @returns {cc.Node} - 创建的子节点
 */
function chuangjian_zijiedian_bingtianjia_label(parentNode, labelText, posY = 0, posX = 0, width = null) {
    const labelNode = new cc.Node();
    parentNode.addChild(labelNode);
    labelNode.setPosition(posX, posY);

    const label = labelNode.addComponent(cc.Label);
    label.string = labelText;
    label.fontSize = 30;
    label.color = new cc.Color().fromHEX("#484848");
    if (width) {
        labelNode.width = width;
        label.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
    }

    return labelNode;
}

/**
 * 处理关闭按钮点击事件
 * @param {cc.Node} rootNode - 根节点
 */
function handle_event_touch_close(rootNode) {
    const activeNode = rootNode.getChildByName("activeNode");
    if (activeNode && activeNode.active) {
        const currentTime = ailin_get_time_day();
        user_default.set_data_for_key("al_not_Show_Install_Shortcut", currentTime);
    }
    rootNode.destroy();
}
